<template>
  <el-dialog
    v-model="dialogVisible"
    :title="dialogTitle"
    width="400px"
    :before-close="handleClose"
    center
  >
    <div class="payment-dialog-content">
      <!-- 支付方式Logo -->
      <div class="payment-logo">
        <el-icon class="logo-icon" :class="logoClass">
          <component :is="logoIcon" />
        </el-icon>
        <div class="payment-name">{{ paymentName }}</div>
      </div>
      
      <!-- 支付金额 -->
      <div class="payment-amount">
        <span class="amount-label">支付金额：</span>
        <span class="amount-value">¥{{ amount }}</span>
      </div>
      
      <!-- 二维码区域 -->
      <div class="qrcode-container">
        <div class="qrcode-placeholder">
          <el-icon class="qrcode-icon"><Picture /></el-icon>
          <div class="qrcode-text">请使用{{ paymentName }}扫码支付</div>
        </div>
      </div>
      
      <!-- 支付说明 -->
      <div class="payment-tips">
        <el-icon><InfoFilled /></el-icon>
        <span>请在15分钟内完成支付，超时订单将自动取消</span>
      </div>
    </div>
    
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">关闭</el-button>
        <el-button type="primary" @click="handlePaymentSuccess">
          支付完成
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { computed, watch, ref } from 'vue'
import { 
  ChatDotRound, 
  Wallet, 
  CreditCard, 
  Picture, 
  InfoFilled 
} from '@element-plus/icons-vue'

// Props
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  paymentMethod: {
    type: String,
    default: 'wechat'
  },
  amount: {
    type: Number,
    default: 0
  }
})

// Emits
const emit = defineEmits(['update:visible', 'close', 'payment-success'])

// 对话框可见性
const dialogVisible = ref(props.visible)

// 监听外部visible变化
watch(() => props.visible, (newValue) => {
  dialogVisible.value = newValue
})

// 监听内部visible变化
watch(dialogVisible, (newValue) => {
  emit('update:visible', newValue)
})

// 支付方式配置
const paymentConfig = {
  wechat: {
    name: '微信支付',
    icon: ChatDotRound,
    class: 'wechat-logo'
  },
  alipay: {
    name: '支付宝',
    icon: Wallet,
    class: 'alipay-logo'
  },
  unionpay: {
    name: '银联支付',
    icon: CreditCard,
    class: 'unionpay-logo'
  }
}

// 计算属性
const dialogTitle = computed(() => {
  return `${paymentConfig[props.paymentMethod]?.name || ''}支付`
})

const paymentName = computed(() => {
  return paymentConfig[props.paymentMethod]?.name || ''
})

const logoIcon = computed(() => {
  return paymentConfig[props.paymentMethod]?.icon || ChatDotRound
})

const logoClass = computed(() => {
  return paymentConfig[props.paymentMethod]?.class || ''
})

// 处理关闭
const handleClose = () => {
  dialogVisible.value = false
  emit('close')
}

// 处理支付完成
const handlePaymentSuccess = () => {
  emit('payment-success')
  handleClose()
}
</script>

<style scoped>
.payment-dialog-content {
  text-align: center;
  padding: 20px 0;
}

.payment-logo {
  margin-bottom: 24px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.wechat-logo {
  color: #07c160;
}

.alipay-logo {
  color: #1677ff;
}

.unionpay-logo {
  color: #e74c3c;
}

.payment-name {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

.payment-amount {
  margin-bottom: 24px;
  padding: 12px;
  background-color: #f5f7fa;
  border-radius: 6px;
}

.amount-label {
  font-size: 14px;
  color: #606266;
}

.amount-value {
  font-size: 20px;
  font-weight: 600;
  color: #e74c3c;
  margin-left: 8px;
}

.qrcode-container {
  margin-bottom: 24px;
}

.qrcode-placeholder {
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border: 2px dashed #d3d3d3;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #fafafa;
}

.qrcode-icon {
  font-size: 64px;
  color: #c0c4cc;
  margin-bottom: 12px;
}

.qrcode-text {
  font-size: 14px;
  color: #909399;
}

.payment-tips {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background-color: #fff7e6;
  border: 1px solid #ffd591;
  border-radius: 4px;
  color: #fa8c16;
  font-size: 13px;
}

.dialog-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
}
</style>